package com.example.knowledgeget1.FileOperate;

import com.example.knowledgeget1.Common.ResponseResult;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/file")
public class FileChatController {

    private final FileChatService fileChatService;

    @Autowired
    public FileChatController(FileChatService fileChatService) {
        this.fileChatService = fileChatService;
    }

    @PostMapping("/upload")
    public ResponseResult handleFileUploadAndChat(@RequestParam("file") MultipartFile file) {
        try {
            List<Map<String, String>> jsonData = fileChatService.uploadFile(file);
            return ResponseResult.success(jsonData);
        } catch (IOException e) {
            e.printStackTrace();
            return ResponseResult.fail();
        }
    }
    //上传需要分析知识点的内容列表
    @PostMapping("/pdf/processContents")
    public ResponseResult handleContentProcessing(@RequestBody ContentRequest contentRequest) {
        try {
            List<List<Map<String, String>>> results = fileChatService.queryModelWithContent(contentRequest.getContents());
            return ResponseResult.success(results);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.fail();
        }
    }

}
